<!--
 * @Descripttion: 
 * @Author: liuYaoYu
 * @Date: 2021-12-16 16:18:22
 * @LastEditors: liuYaoYu
 * @LastEditTime: 2021-12-16 16:28:11
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 字符类 [] 表示一系列中 可供选择 匹配一个就行了
        var rg=/[abc]/ //只要包含 a|b|c都返回true
        console.log(rg.test("a"));
        console.log(rg.test("b"));
        console.log(rg.test("c"));
        console.log(rg.test("color"));
        console.log(rg.test("red"));//false
        console.log('----------------');
        var reg=/^[abc]$/;//三选一 只 a 或者 b 或者c
        console.log(reg.test("a"));
        console.log(reg.test("b"));
        console.log(reg.test("c"));
        console.log(reg.test("d"));
        console.log('----------------');
        var reg=/^[a-z]$/;// 26个英文字母
        console.log(reg.test('ab')); //false
        console.log(reg.test('z')); //true
        console.log('----------------');
        // 字符组合
        var reg1=/^[a-zA-Z0-9_-]$/;// 字符组合
        console.log(reg1.test('a'));
        console.log(reg1.test('A'));
        console.log(reg1.test('0'));
        console.log(reg1.test('-'));
        console.log(reg1.test('_'));
        console.log(reg1.test('!'));
        console.log('----------------');
        var reg2=/^[^a-zA-Z0-9_-]$/;// 如果中括号里面出现^ 就是取反的意思 就是不能包括这些
        console.log(reg2.test('a'));
        console.log(reg2.test('A'));
        console.log(reg2.test('0'));
        console.log(reg2.test('-'));
        console.log(reg2.test('_'));
        console.log(reg2.test('!'));
    </script>
</body>
</html>